import {Component, OnInit} from '@angular/core';
import {_HttpClient} from '@delon/theme';
import {BusinessService} from '../business.service';
import {Business} from '../business';
import {NzMessageService} from 'ng-zorro-antd';

@Component({
    selector: 'app-list',
    templateUrl: './list.component.html',
})
export class ListComponent implements OnInit {

    data: Business[] = [];

    constructor(
        private businessService: BusinessService,
        private msg: NzMessageService,
    ) {
    }

    ngOnInit() {
        this.getlist();
    }

    getlist() {
        this.businessService.getBuiness().subscribe(res => {
            this.data = res['list'];
        });
    }

    del(item: Business, index: number) {
        this.data = [...this.data.splice(0, index), ...this.data.splice(index + 1, this.data.length)];
        this.businessService.delBusiness(item.id).subscribe(res => {
            this.msg.success('删除成功');
        }, __ => {

        });
    }
}
